package com.tool4j.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tool4j.entity.GenerateCodeLog;
import com.tool4j.entity.params.PageParams;
import com.tool4j.mapper.GenerateCodeLogMapper;
import com.tool4j.service.GenerateCodeLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Deng.WeiPing
 * @since 2025-08-26 13:54:16
 */
@Service
@Slf4j
public class GenerateCodeLogServiceImpl extends ServiceImpl<GenerateCodeLogMapper, GenerateCodeLog> implements GenerateCodeLogService {

    @Autowired
    private GenerateCodeLogMapper generateCodeLogMapper;

    @Override
    public Page<GenerateCodeLog> findPage(Long userId, PageParams<GenerateCodeLog> params) {
        LambdaQueryWrapper<GenerateCodeLog> query = Wrappers.lambdaQuery(GenerateCodeLog.class)
                .eq(GenerateCodeLog::getUserId, userId);
        Page<GenerateCodeLog> page = params.getPage().setOptimizeCountSql(false);
        return generateCodeLogMapper.selectPage(page, query);
    }

    @Override
    public List<GenerateCodeLog> findList(Long userId, GenerateCodeLog params) {
        LambdaQueryWrapper<GenerateCodeLog> query = Wrappers.lambdaQuery(GenerateCodeLog.class)
                .eq(GenerateCodeLog::getUserId, userId);
        return generateCodeLogMapper.selectList(query);
    }

    @Override
    public GenerateCodeLog findById(Long id) {
        return generateCodeLogMapper.selectById(id);
    }

    @Override
    public boolean insert(GenerateCodeLog generateCodeLog) {
        return save(generateCodeLog);
    }

    @Override
    public int delete(Long id) {
        return generateCodeLogMapper.deleteById(id);
    }

}
